module shz{
    /** 水浒传游戏逻辑 */
    export class GameLogic{
        /** 格子显示类型 */
        public static item = ["futou", "yin", "dadao", "lu", "lin", "song", "ttxd", "zyt", "shz"]
        /** 定义中奖的线 */
        public static lines = [
            [[1, 0], [1, 1], [1, 2], [1, 3], [1, 4]], 
            [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4]],
            [[2, 0], [2, 1], [2, 2], [2, 3], [2, 4]],
            [[0, 0], [1, 1], [2, 2], [1, 3], [0, 4]],
            [[2, 0], [1, 1], [0, 2], [1, 3], [2, 4]],
            [[0, 0], [0, 1], [1, 2], [0, 3], [0, 4]],
            [[2, 0], [2, 1], [1, 2], [2, 3], [2, 4]],
            [[1, 0], [2, 1], [2, 2], [2, 3], [1, 4]],
            [[1, 0], [0, 1], [0, 2], [0, 3], [1, 4]]
        ];
        /** 检查有哪些线中奖了 */
        public static checkLine(items:number[][]):any[]{
            let ln = [];
            for(let i=0;i<9;i++){
                let itm = [], cln = GameLogic.lines[i], itp = -1;
                for(let j=0;j<5;j++){
                    itm.push(cln[j]);
                    if(itm.length == 1){
                        if(items[cln[j][0]][cln[j][1]] != 8) itp = items[cln[j][0]][cln[j][1]];
                        continue;
                    } 
                    if(!(items[cln[j][0]][cln[j][1]] == 8 || itp == -1 || items[cln[j][0]][cln[j][1]] == itp)){
                        if(itm.length > 3) {
                            itm.pop();
                            break;
                        }
                        itm = itm.slice(itm.length-1);
                    }
                    if(items[cln[j][0]][cln[j][1]] != 8) itp = items[cln[j][0]][cln[j][1]];
                }
                if(itm.length > 2) {
                    itm.push(i);
                    ln.push(itm);
                }
            }
            return ln;
        }
    }
}